/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gbbmgmt;

import java.awt.*;
import java.awt.print.*;
import java.awt.MediaTracker;
import java.net.URL;
import java.util.*;
import java.io.*;
import java.net.MalformedURLException;
import java.awt.Image;
import java.text.*;

/**
 *
 * @author dchapman
 */
public class PrintRecipe {
    // private instance declarations
    private final static int POINTS_PER_INCH = 72;

    //Create Number Formater for displaying numbers.
    public NumberFormat f2 = new DecimalFormat("#0.00");
    public NumberFormat f0 = new DecimalFormat("#0");
    public NumberFormat f3 = new DecimalFormat("#0.000");

    public void PrintSO (){
        //Create a new printer job object.
        PrinterJob printJob = PrinterJob.getPrinterJob();

        //Create a new book and add pages to it
        Book book = new Book();

        //Add the sales order page to the book.
        book.append(new RecpPage(), printJob.defaultPage());

        //Tell the printJob to use the Book as the Pageable object.
        printJob.setPageable(book);

        //Show the print dialog box. If user clicks the
        //print button, we then proceed to print, else we cancel
        //the process.
        if (printJob.printDialog()){
            try {
                printJob.print();
            } catch (Exception PrintException){
                PrintException.printStackTrace();
            }
        }
    }

     private class RecpPage extends Component implements Printable {

        //this is the class to implement the Sales Order Printing.
        public int print (Graphics g, PageFormat pageFormat, int page){

            //Open Database Connection
            DBA.openDBCon();

            //Get Reicpe Data based on recipe ID.
            DBA.GetRecipesData(Global.PrintRecipeID);

            //Create the Graphics2D object.
            Graphics2D g2d = (Graphics2D) g;

            //Translate the origin to 0,0 for the top left corner
            g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

            //Set the default drawing color to black.
            g2d.setPaint(Color.BLACK);

            //---Section 1 (Header)
            //Print the header
            String titleText = "Grimm Brothers Brewhouse LLC";
            Font titleFont = new Font ("helvetica", Font.BOLD, 18);
            g2d.setFont(titleFont);

            //Comput the right alignment on the page.
            FontMetrics fontMetrics = g2d.getFontMetrics();
            double titleX = (pageFormat.getImageableWidth()) - (fontMetrics.stringWidth(titleText));
            double titleY = 10;
            g2d.drawString (titleText, (int) titleX, (int) titleY);

            //Print the address.
            String addressText0 = "Recipe: " + DBA.RName + " Rev - " + Integer.toString(DBA.RRev);
            String addressText1 = "RID#" + Integer.toString(DBA.RecpID);
            Font addressFont = new Font ("helvetica", Font.PLAIN, 12);
            int linespace = 14;
            int doublespace = 28;
            int addressY = 14;
            g2d.setFont(addressFont);

            //Compute the right alignment for the address info.
            fontMetrics = g2d.getFontMetrics();
            double addressX = (pageFormat.getImageableWidth()) - (fontMetrics.stringWidth(addressText0));
            g2d.drawString (addressText0, (int) addressX, (addressY + (linespace * 1)));
            addressX = (pageFormat.getImageableWidth()) - (fontMetrics.stringWidth(addressText1));
            g2d.drawString (addressText1, (int) addressX, (addressY + (linespace * 2)));

            Font regularFont = new Font ("helvetica", Font.PLAIN, 10);
            Font boldFont = new Font ("helvetica", Font.BOLD, 10);

            //Set up columns.
            double col1 = 0;
            double col2 = ((pageFormat.getImageableWidth())/8)*3;
            double col3 = ((pageFormat.getImageableWidth())/8)*4;
            double col4 = ((pageFormat.getImageableWidth())/8)*5;
            double col5 = ((pageFormat.getImageableWidth())/8)*6;
            double col6 = ((pageFormat.getImageableWidth())/8)*7;
            double col7 = ((pageFormat.getImageableWidth())/8)*8;

            //Variables for use during calculation of recipes.
            double GUtot = (DBA.RGT - 1)*1000 * DBA.RVol * 31;
            double VolFinal = DBA.RVol * 31;

            double LBTOT = 0;
            double LBNM = 0;
            double SRMTOT = 0;

            //---Section 2 (Malt)
            int maltY = 25;
            String text="";
            maltY += doublespace;

            g2d.setFont(regularFont);
            text = "Target Gravity = " + f3.format(DBA.RGT);
            g2d.drawString(text, 0, maltY);

            maltY += linespace;
            text = "Target Volume = " + f2.format(DBA.RVol) + " BBL";
            g2d.drawString(text, 0, maltY);

            //Get Malt data if id is chosen.
            double lbs = 0;
            double srm = 0;
            double bagnum = 0;
            double remain = 0;

            maltY += doublespace;
            g2d.setFont(boldFont);
            text="Malt";
            g2d.drawString(text, 0, maltY);
            maltY += linespace;
            g2d.setFont(boldFont);
            text = "Malt Type:";
            g2d.drawString(text, (int)col1, maltY);
            text = "Percent:";
            g2d.drawString(text, (int)col2, maltY);
            text = "Pounds:";
            g2d.drawString(text, (int)col3, maltY);
            text = "Efficiency:";
            g2d.drawString(text, (int)col4, maltY);
            text = "Bags, Lbs.:";
            g2d.drawString(text, (int)col5, maltY);

            g2d.setFont(regularFont);
            if(DBA.Mpct01>0){
                DBA.GetMaltData(Integer.toString(DBA.MName01));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct01) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct01 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct02>0){
                DBA.GetMaltData(Integer.toString(DBA.MName02));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct02) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct02 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct03>0){
                DBA.GetMaltData(Integer.toString(DBA.MName03));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct03) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct03 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct04>0){
                DBA.GetMaltData(Integer.toString(DBA.MName04));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct04) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct04 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct05>0){
                DBA.GetMaltData(Integer.toString(DBA.MName05));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct05) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct05 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct06>0){
                DBA.GetMaltData(Integer.toString(DBA.MName06));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct06) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct06 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct07>0){
                DBA.GetMaltData(Integer.toString(DBA.MName07));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct07) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct07 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct08>0){
                DBA.GetMaltData(Integer.toString(DBA.MName08));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct08) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct08 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct09>0){
                DBA.GetMaltData(Integer.toString(DBA.MName09));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct09) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct09 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }
            if(DBA.Mpct10>0){
                DBA.GetMaltData(Integer.toString(DBA.MName10));
                maltY += linespace;
                text = DBA.MaltName;
                g2d.drawString(text, (int)col1, maltY);

                text = f0.format(DBA.Mpct10) + "%";
                g2d.drawString(text, (int)col2, maltY);

                lbs = (((double)DBA.Mpct10 / 100) * GUtot) / (((double)DBA.MaltEff / 100) * (double)DBA.MaltSG);
                text = f2.format(lbs) + " Lbs.";
                g2d.drawString(text, (int)col3, maltY);

                text = f2.format(DBA.MaltEff) + "%";
                g2d.drawString(text, (int)col4, maltY);

                bagnum = Math.floor(lbs / (double)DBA.MaltBagLbs);
                remain = lbs - (bagnum * (double)DBA.MaltBagLbs);
                text = f0.format(bagnum) + " Bags, " + f2.format(remain) + " Lbs.";
                g2d.drawString(text, (int)col5, maltY);

                srm = (DBA.MaltColor * lbs) / VolFinal;
                if (DBA.MaltEff == 100){
                    LBNM += lbs;
                } else {
                    LBTOT += lbs;
                    LBNM += lbs;
                }
                SRMTOT += srm;
            }

            //Print out total stats.
            srm = ((SRMTOT*0.3)+4.7);
            maltY += doublespace;
            text = "Color: " + f2.format(srm);
            g2d.drawString(text, (int)col1, maltY);
            text = "Mash Total: " + f2.format(LBTOT) + " Lbs.";
            g2d.drawString(text, (int)col2, maltY);
            text = "Total Pounds: " + f2.format(LBNM) + " Lbs.";
            g2d.drawString(text, (int)col4, maltY);

            //---SECTION 3: Water Data
            maltY += doublespace;
            g2d.setFont(boldFont);
            text="Water Additions:";
            g2d.drawString(text, 0, maltY);
            g2d.setFont(regularFont);
            maltY += linespace;
            text = "Gypsum = " + f0.format(DBA.gGypsum) + " grams";
            g2d.drawString(text, (int)col1, maltY);
            text = "CaCl = " + f0.format(DBA.gCaCl) + " grams";
            g2d.drawString(text, (int)col3, maltY);
            maltY += linespace;
            text = "Epsom Salt = " + f0.format(DBA.gEpsomSalt) + " grams";
            g2d.drawString(text, (int)col1, maltY);
            text = "Chalk = " + f0.format(DBA.gChalk) + " grams";
            g2d.drawString(text, (int)col3, maltY);
            maltY += linespace;
            text = "Table Salt = " + f0.format(DBA.gTableSalt) + " grams";
            g2d.drawString(text, (int)col1, maltY);

            //---SECTION 4: Hop Data

            //Calculations for Hops
            double BoilVol = ((VolFinal + 0.5)/(0.96 * 0.9542));
            double Gstart = ((GUtot/BoilVol)+1000)/1000;
            double CGRAV = (1+((Gstart - 1.05)/2));
            if ((1+((Gstart - 1.05)/2))<1){
                CGRAV = 1;
            }
            double IBUTOT = 0;
            double NumBitter = 0;

            //Calculate total IBU from recipe that are not bittering hops.
            double HopNumber = 0;
            double HopAcid = 0;
            double OldIBU = 0;

            double eff = 0;
            double ibu = 0;

            //First Hop.
            DBA.GetHopsData(Integer.toString(DBA.HName01));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct01);
            ibu = ((((double)DBA.hlbs01 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct01 < 60) || (DBA.AApct01 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                HopNumber = (double)DBA.HName01;
                HopAcid = (double)DBA.HopAA;
                OldIBU = ibu;
            }

            //Second Hop
            DBA.GetHopsData(Integer.toString(DBA.HName02));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct02);
            ibu = ((((double)DBA.hlbs02 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct02 < 60) || (DBA.AApct02 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName02;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //Third Hop
            DBA.GetHopsData(Integer.toString(DBA.HName03));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct03);
            ibu = ((((double)DBA.hlbs03 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct03 < 60) || (DBA.AApct03 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName03;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //4th Hop
            DBA.GetHopsData(Integer.toString(DBA.HName04));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct04);
            ibu = ((((double)DBA.hlbs04 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct04 < 60) || (DBA.AApct04 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName04;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //5th Hop
            DBA.GetHopsData(Integer.toString(DBA.HName05));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct05);
            ibu = ((((double)DBA.hlbs05 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct05 < 60) || (DBA.AApct05 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName05;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //6th Hop
            DBA.GetHopsData(Integer.toString(DBA.HName06));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct06);
            ibu = ((((double)DBA.hlbs06 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct06 < 60) || (DBA.AApct06 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName06;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //7th Hop
            DBA.GetHopsData(Integer.toString(DBA.HName07));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct07);
            ibu = ((((double)DBA.hlbs07 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct07 < 60) || (DBA.AApct07 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName07;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //8th Hop
            DBA.GetHopsData(Integer.toString(DBA.HName08));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct08);
            ibu = ((((double)DBA.hlbs08 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct08 < 60) || (DBA.AApct08 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName08;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //9th Hop
            DBA.GetHopsData(Integer.toString(DBA.HName09));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct09);
            ibu = ((((double)DBA.hlbs09 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct09 < 60) || (DBA.AApct09 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName09;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }
            //10th Hop
            DBA.GetHopsData(Integer.toString(DBA.HName10));
            eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct10);
            ibu = ((((double)DBA.hlbs10 * 16)*eff*((double)DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
            if((DBA.AApct10 < 60) || (DBA.AApct10 > 80)){
                IBUTOT += ibu;
            } else {
                NumBitter++;
                if(HopAcid <= DBA.HopAA){
                    HopNumber = DBA.HName10;
                    HopAcid = DBA.HopAA;
                    IBUTOT += OldIBU;
                } else {
                    IBUTOT += ibu;
                }
                OldIBU = ibu;
            }

            double IBULEFT = (double)DBA.RIBU - IBUTOT;
            IBUTOT = 0;

            //Print out Hops.
            maltY += doublespace;
            g2d.setFont(boldFont);
            text = "Kettle Hop Additions:";
            g2d.drawString(text, 0, maltY);

            double lbdisp = 0;
            remain = 0;

            maltY += linespace;
            text="Hop Name:";
            g2d.drawString(text, (int)col1, maltY);
            text="Alpha %:";
            g2d.drawString(text, (int)col2, maltY);
            text="Time:";
            g2d.drawString(text, (int)col3, maltY);
            text="Pounds:";
            g2d.drawString(text, (int)col4, maltY);
            text = "Lbs., Oz.:";
            g2d.drawString(text, (int)col5, maltY);
            g2d.setFont(regularFont);

            if(DBA.hlbs01 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName01));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct01);
                if((DBA.AApct01<80)&&(DBA.AApct01>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs01 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs01*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                if(DBA.fwh1){
                    text="FWH";
                    g2d.drawString(text, (int)col3, maltY);
                } else {
                    text=Float.toString(DBA.AApct01) + " min";
                    g2d.drawString(text, (int)col3, maltY);
                }
                text=f2.format(DBA.hlbs01) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs01);
                remain = 16*(DBA.hlbs01-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs02 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName02));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct02);
                if((DBA.AApct02<80)&&(DBA.AApct02>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs02 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs02*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                if(DBA.fwh2){
                    text="FWH";
                    g2d.drawString(text, (int)col3, maltY);
                } else {
                    text=Float.toString(DBA.AApct02) + " min";
                    g2d.drawString(text, (int)col3, maltY);
                }
                text=f2.format(DBA.hlbs02) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs02);
                remain = 16*(DBA.hlbs02-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs03 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName03));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct03);
                if((DBA.AApct03<80)&&(DBA.AApct03>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs03 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs03*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct03) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs03) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs03);
                remain = 16*(DBA.hlbs03-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs04 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName04));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct04);
                if((DBA.AApct04<80)&&(DBA.AApct04>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs04 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs04*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct04) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs04) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs04);
                remain = 16*(DBA.hlbs04-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs05 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName05));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct05);
                if((DBA.AApct05<80)&&(DBA.AApct05>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs05 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs05*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct05) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs05) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs05);
                remain = 16*(DBA.hlbs05-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs06 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName06));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct06);
                if((DBA.AApct06<80)&&(DBA.AApct06>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs06 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs06*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct06) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs06) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs06);
                remain = 16*(DBA.hlbs06-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs07 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName07));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct07);
                if((DBA.AApct07<80)&&(DBA.AApct07>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs07 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs07*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct07) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs07) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs07);
                remain = 16*(DBA.hlbs07-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs08 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName08));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct08);
                if((DBA.AApct08<80)&&(DBA.AApct08>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs08 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs08*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct08) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs08) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs08);
                remain = 16*(DBA.hlbs08-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs09 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName09));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct09);
                if((DBA.AApct09<80)&&(DBA.AApct09>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs09 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs09*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct09) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs09) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs09);
                remain = 16*(DBA.hlbs09-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }
            if(DBA.hlbs10 > 0){
                DBA.GetHopsData(Integer.toString(DBA.HName10));
                eff = DBA.GetUtil(DBA.HopWhole, (long)DBA.AApct10);
                if((DBA.AApct10<80)&&(DBA.AApct10>60)&&(DBA.HopAA==HopAcid)){
                    ibu = IBULEFT;
                    DBA.hlbs10 = (float)(((ibu*VolFinal*CGRAV)/(7489*eff*(DBA.HopAA/100)))/16);

                } else {
                    ibu = (((DBA.hlbs10*16)*eff*(DBA.HopAA/100)*7489)/(VolFinal*CGRAV));
                }
                maltY += linespace;
                text=DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text=Float.toString(DBA.HopAA) + "%";
                g2d.drawString(text, (int)col2, maltY);
                text=Float.toString(DBA.AApct10) + " min";
                g2d.drawString(text, (int)col3, maltY);
                text=f2.format(DBA.hlbs10) + " Lbs.";
                g2d.drawString(text, (int)col4, maltY);
                lbdisp = Math.floor((double)DBA.hlbs10);
                remain = 16*(DBA.hlbs10-lbdisp);
                text = (Double.toString(lbdisp) + " Lbs., " + f2.format(remain) + " Oz.");
                g2d.drawString(text, (int)col5, maltY);
                IBUTOT += ibu;
            }

            maltY += doublespace;
            text = "Total IBUs = " + f2.format(IBUTOT);
            g2d.drawString(text, 0, maltY);


            //Print out Mash Info.
            maltY += doublespace;
            g2d.setFont(boldFont);
            text = "Mash:";
            g2d.drawString(text, 0, maltY);
            g2d.setFont(regularFont);
            maltY += linespace;
            text="Ratio (Qtr/Lb) = " + f2.format(DBA.ratio);
            g2d.drawString(text, (int)col1, maltY);
            double MashWater = (((double)DBA.ratio * LBTOT)/4/31);
            double tinit = 68;
            double WaterTemp = (((0.2/(double)DBA.ratio)*((double)DBA.ttemp-tinit))+(double)DBA.ttemp);
            text="Mash Water Volume = " + f2.format(MashWater) + " BBL";
            g2d.drawString(text, (int)col3, maltY);
            maltY += linespace;
            text="Target Temp = " + f2.format(DBA.ttemp) + "°F";
            g2d.drawString(text, (int)col1, maltY);
            text="Mash Water Temp = " + f2.format(WaterTemp) + "°F";
            g2d.drawString(text, (int)col3, maltY);

            //Print out Yeast Info.
            maltY += doublespace;
            g2d.setFont(boldFont);
            text = "Yeast:";
            g2d.drawString(text, 0, maltY);
            g2d.setFont(regularFont);
            maltY += linespace;
            DBA.GetYeastData(Integer.toString(DBA.YeastName));
            text = "Yeast = " + DBA.YeastDesc;
            g2d.drawString(text, (int)col1, maltY);
            text = "Fermentation Temp = " + f2.format(DBA.PTemp) + "°F";
            g2d.drawString(text, (int)col3, maltY);

            //Print out Dry Hopping.
            maltY += doublespace;
            g2d.setFont(boldFont);
            text = "Dry Hopping:";
            g2d.drawString(text, 0, maltY);
            maltY += linespace;
            text = "Hop Name:";
            g2d.drawString(text, (int)col1, maltY);
            text = "Days:";
            g2d.drawString(text, (int)col2, maltY);
            text = "Pounds:";
            g2d.drawString(text, (int)col3, maltY);
            g2d.setFont(regularFont);

            if(DBA.DHLbs1>0){
                maltY += linespace;
                DBA.GetHopsData(Integer.toString(DBA.DHHop1));
                text = DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text = Integer.toString(DBA.DHDay1);
                g2d.drawString(text, (int)col2, maltY);
                text = f2.format(DBA.DHLbs1);
                g2d.drawString(text, (int)col3, maltY);
            }
            if(DBA.DHLbs2>0){
                maltY += linespace;
                DBA.GetHopsData(Integer.toString(DBA.DHHop2));
                text = DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text = Integer.toString(DBA.DHDay2);
                g2d.drawString(text, (int)col2, maltY);
                text = f2.format(DBA.DHLbs2);
                g2d.drawString(text, (int)col3, maltY);
            }
            if(DBA.DHLbs3>0){
                maltY += linespace;
                DBA.GetHopsData(Integer.toString(DBA.DHHop3));
                text = DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text = Integer.toString(DBA.DHDay3);
                g2d.drawString(text, (int)col2, maltY);
                text = f2.format(DBA.DHLbs3);
                g2d.drawString(text, (int)col3, maltY);
            }
            if(DBA.DHLbs4>0){
                maltY += linespace;
                DBA.GetHopsData(Integer.toString(DBA.DHHop4));
                text = DBA.HopName;
                g2d.drawString(text, (int)col1, maltY);
                text = Integer.toString(DBA.DHDay4);
                g2d.drawString(text, (int)col2, maltY);
                text = f2.format(DBA.DHLbs4);
                g2d.drawString(text, (int)col3, maltY);
            }
            

            //Close database connection.
            DBA.closeDBCon();

            return (PAGE_EXISTS);
        }

    }
}
